
#include <boost/numeric/conversion/cast.hpp>

#include <cassert>
#include <cstdio>

#include "numeric_cast_test.h"


void	numeric_cast_test()
{
	int i = boost::numeric_cast< int >( 1.234 );
	assert( i == 1 );
	printf( "i: %d\n", i );

	double d = boost::numeric_cast< double >( 12345 );
	assert( d == 12345 );
	printf( "d: %f\n", d );


	try
	{
		short s = boost::numeric_cast< short >( 123456 );
		assert( false );
	}
	catch( boost::numeric::positive_overflow& e )
	{
		printf( "catch boost::numeric::positive_overflow: %s\n", e.what() );
	}

	try
	{
		short s = boost::numeric_cast< short >( -123456 );
		assert( false );
	}
	catch( boost::numeric::negative_overflow& e )
	{
		printf( "catch boost::numeric::positive_overflow: %s\n", e.what() );
	}
}
